//
//  FFRechargeInputCell.m
//  LLWallet
//
//  Created by tt on 2020/8/17.
//

#import "FFRechargeInputCell.h"

@implementation FFRechargeInputModel

- (Class)cell {
    return FFRechargeInputCell.class;
}

- (NSNumber *)showArrow {
    return @(false);
}
@end

@interface FFRechargeInputCell ()

@property(nonatomic,strong) UILabel *titleLbl;
@property(nonatomic,strong) UILabel *moneyLbl;
@property(nonatomic,strong) UITextField *amountFd;

@property(nonatomic,strong) FFRechargeInputModel *model;

@end

@implementation FFRechargeInputCell

+ (CGSize)sizeForModel:(FFRechargeInputModel *)model {
    return CGSizeMake(WKScreenWidth, 80.0f);
}

- (void)setupUI {
    [super setupUI];
    [self.contentView addSubview:self.titleLbl];
    [self.contentView addSubview:self.moneyLbl];
    [self.contentView addSubview:self.amountFd];
}

- (UILabel *)titleLbl {
    if(!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = [[WKApp shared].config appFontOfSize:16.0f];
        _titleLbl.text = LLang(@"充值金额");
        [_titleLbl sizeToFit];
    }
    return _titleLbl;
}

- (UITextField *)amountFd {
    if(!_amountFd) {
        _amountFd = [[UITextField alloc] init];
        _amountFd.keyboardType = UIKeyboardTypeNumberPad;
        [_amountFd setPlaceholder:LLang(@"请输入充值金额")];
        [_amountFd addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventEditingChanged];
    }
    return _amountFd;
}

-(void) textChange:(UITextField *)textField {
    if(self.model.onChange) {
        self.model.onChange(textField.text);
    }
}

- (UILabel *)moneyLbl {
    if(!_moneyLbl) {
        _moneyLbl = [[UILabel alloc] init];
        _moneyLbl.text = @"¥";
        [_moneyLbl setFont:[[WKApp shared].config appFontOfSizeMedium:20.0f]];
        [_moneyLbl sizeToFit];
    }
    return _moneyLbl;
}

- (void)refresh:(FFRechargeInputModel *)model {
    [super refresh:model];
    self.model = model;
    if(model.value && model.value.floatValue>0) {
        self.amountFd.text = model.value.stringValue;
    }else {
        self.amountFd.text = @"";
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.titleLbl.lim_left = 15.0f;
    self.titleLbl.lim_top = 10.0f;
    
    self.moneyLbl.lim_top = self.titleLbl.lim_bottom + 10.0f;
    self.moneyLbl.lim_left = self.titleLbl.lim_left;
    
    self.amountFd.lim_top = self.titleLbl.lim_bottom + 5.0f;
    self.amountFd.lim_left = self.moneyLbl.lim_right+5.0f;
    self.amountFd.lim_width = self.lim_width - self.moneyLbl.lim_right;
    self.amountFd.lim_height = 40.0f;
}

@end
